package com.ziyear.ssm.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ziyear.ssm.bean.User;
import com.ziyear.ssm.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	private UserService userService;
	
	@RequestMapping("login.action")
	public String login(User user,HttpServletRequest request) {
		User existUser = userService.login(user);
		if(existUser != null) {
			request.getSession().setAttribute("user", existUser);
			return "redirect:http://localhost:8080/boot-ssm/customer/showlist.action";
		}else {
			request.setAttribute("msg", "用户名或密码错误!!!");
			return "forward:/index.jsp";
		}
	}
	
	@RequestMapping("logout.action")
	@ResponseBody
	public String logout(HttpServletRequest request) {
		request.getSession().removeAttribute("user");
		return "ok";
	}
}
